<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/static/css/style.css">
    <link rel="icon" href="__PUBLIC__/static/image/code.png">
</head>
<body>

<div class="login-main">
    <header class="layui-elip">后台登录</header>
    <form class="layui-form" method="post" id="loginform">
        <div class="layui-input-inline">
            <input type="text" name="user_name" required lay-verify="required" placeholder="用户名" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="password" name="password" required lay-verify="required" placeholder="密码" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" name="captcha" placeholder="验证码" class="layui-input" style="width:100px;float:left;margin-right:10px">
            <div><img src="{:url('verify')}" alt="captcha" height="38px" onclick="this.src='{:url('verify')}?'+Math.random()" />点击刷新</div>
        </div>
        
        <div class="layui-input-inline login-btn">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">登录</button>
        </div>
        <hr/>
        <p><a href="javascript:;" class="fl">立即注册</a><a href="javascript:;" class="fr">忘记密码？</a></p>
        {:token()}
    </form>
</div>


<script src="__PUBLIC__/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form'], function () {
        // 操作对象
        var form = layui.form
                , $ = layui.jquery
                ,layer = layui.layer;


        form.verify({
            account: function (value) {
                if (value == "") {
                    return "请输入用户名";
                }
            },
            password: function (value) {
                if (value == "") {
                    return "请输入密码";
                }
            },
            code: function (value) {
                if (value == "") {
                    return "请输入验证码";
                }
            }
        });

        form.on('submit(demo1)', function(data){
            $.post('{:url('admin/Login/index')}',$('#loginform').serialize(),function(data){
                if(data.code == 1){
                    layer.msg(data.msg);
                    location.href=data.url;
                }else{
                    //alert('dfsd');
                    console.log(data);
                    layer.msg(data.msg);
                }
            });
            return false;
        });
    });


</script>
</body>
</html>